package com.lxd.filter.Impl;

import com.lxd.common.constants.CacheConstant;
import com.lxd.common.constants.StrategyConstant;
import com.lxd.common.enums.ExceptionEnums;
import com.lxd.common.exception.StrategyException;
import com.lxd.common.model.StandardSubmit;
import com.lxd.feign.cacheClient;
import com.lxd.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Dongdong
 * @注释 平台级别的黑名单校验
 */
@Service(value = "blackPlants")
@Slf4j
public class BlackPlantsStrategyFilter implements CheckFilter {

    @Autowired
    private cacheClient client;
    @Override
    public void check(StandardSubmit submit) {
        log.info("【策略模块-平台黑名单校验】 开始校验~~~~~");
        //从redis查询 mobile 是否是黑名单
        String mobile = submit.getMobile();
        String s = client.getString(CacheConstant.BLACK + mobile + StrategyConstant.GLOBAL_ID);
        if (StrategyConstant.IS_BLACK.equals(s)){
            //是黑名单
            log.info("【策略模块-平台黑名单校验】 当前手机号mobile={}是黑名单",mobile);
            throw new StrategyException(ExceptionEnums.BLACK_CLIENT);
        }

        log.info("【策略模块-平台黑名单校验】 当前手机号mobile={}不是黑名单，校验通过",mobile);


    }
}
